package table.generation;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class TableGeneratorTest {
	
	SessionFactory sessionFactory = null;
	@BeforeClass
	public void setup(){
		Configuration cfg = new Configuration();
		cfg.configure();
		StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
		serviceRegistryBuilder.applySettings(cfg.getProperties());
		sessionFactory = cfg.buildSessionFactory(serviceRegistryBuilder.build());
	}
	
	@Test
	public void testSequenceGeneration(){		
		Book book = new Book();
		book.setName("Sieve of Eratosthenes");
		
		Session session = sessionFactory.openSession();
		Transaction txn = session.beginTransaction();
		session.save(book);
		txn.commit();
		session.close();		
	}
}
